<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>新增页面</title>
		<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="mainBox">
				<div class="main-container">
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">类别</label>
						<div class="layui-input-inline">
							<select name="stype" lay-verify="required" lay-search>
								<option value="">全部</option>
								<option value="1">儿童言语发展</option>
								<option value="2">儿童言语服务</option>
								<option value="3">成人言语服务</option>
							</select>

						</div>
					</div>
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">数量</label>
						<div class="layui-input-inline">
							<input type="number" name="number" placeholder="" class="layui-input">
						</div>
					</div>






				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
						lay-filter="user-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
		<script src="../../../component/layui/layui.js"></script>
		<script src="../../../component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery','upload'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				var upload = layui.upload;
				$.ajaxSetup({
					headers:{
						'Authorization':window.sessionStorage.getItem("token")
					}
				})
				// 发送 Ajax 请求获取 symtype 数据
				$.ajax({
					url: window.BASEPATH +'survey/getType',
					type: 'get',
					dataType: 'json',
					success: function(result) {
						// 清空下拉框选项
						//alert(result+"????????????");
						//console.log("sssssssssssss",result)
						$('select[name="stype"]').empty();

						// 添加默认的请选择选项
						//ar defaultOption = '<option value="">symType</option>';
						//$('select[name="stype"]').append(defaultOption);

						// 遍历结果，添加每个 symtype 作为选项，并设置 value 为对应 SymType 的 id
						let symtype =  result.data
						//console.log("ttttttttttttttt",result.data)
						//alert(symtype+"????????????");
						for (var i = 0; i < symtype.length; i++) {
							var option = '<option value="' + symtype[i].id + '">' + symtype[i].symtype + '</option>';
							//console.log("sssssssss",$('select[name="stype"]').length)
							$('select[name="stype"]').append(option);
						}

						// 重新渲染下拉框
						form.render('select');
					},
					error: function(error) {
						console.log(error);
					}
				});

				// 初始化下拉框
				form.render('select');
				form.on('submit(user-save)', function(data) {
					$.ajax({
						url: window.BASEPATH+'survey/add',
						data: data.field,
						type: 'post',
						success: function(result) {
							if (result.code==0) {
								layer.msg(result.msg, {
									icon: 1,
									time: 1000
								}, function() {
									parent.layer.close(parent.layer.getFrameIndex(window
										.name)); //关闭当前页
									parent.layui.table.reload("user-table");
								});
							} else {
								layer.msg(result.msg, {
									icon: 2,
									time: 1000
								});
							}
						}
					})
					return false;
				});
			})
		</script>
		<script>
		</script>
	</body>
</html>
